#ifndef APP_FRAME_H
#define APP_FRAME_H

#include <wx/frame.h>
#include <cassert>
#include <vector>

#include "keyword.h"

class wxAuiNotebook;
class wxAuiNotebookEvent;
class wxSizer;
class wxStatusBar;
class wxPoint;
class wxSize;

class NotesPanelBase;
class NotesPanel;
class EditsPanel;
class KeywordsPanel;
class KeywordDialog;
class NoteDialog;
class DBase;
class Note;
class NoteFilter;

using std::vector;

class AppFrame: public wxFrame
{
    DBase*              db;
    bool                db_downloaded;     // set to 1 after user downloads DB - to make sure he doesn't accidentally use outdated local copy
    bool                fullscreen;

    wxAuiNotebook*      notebook;
    void OnTabChanged(wxAuiNotebookEvent& event);
    void OnTabClosed(wxAuiNotebookEvent& event);
    wxSizer*            tabs_sizer;
    wxStatusBar*        status_bar;

    int                 new_note_counter;
    int                 new_keyword_counter;

    void OnClose(wxCloseEvent& event);
    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
    void OnSettings(wxCommandEvent& event);
    void OnDownload(wxCommandEvent& event);
    void OnExport(wxCommandEvent& event);
    void OnUpload(wxCommandEvent& event);
    void OnNewNote(wxCommandEvent& event);
    void OnEditNote(wxCommandEvent& event);
    void OnFindNotes(wxCommandEvent& event);
    void OnNewKeyword(wxCommandEvent& event);
    void OnFindKeywords(wxCommandEvent& event);
    void OnEditFilter(wxCommandEvent& event);
    void OnDateFilter(wxCommandEvent& event);
    void OnEditDateFilter(wxCommandEvent& event);
    void OnEditedNotes(wxCommandEvent& event);
    void OnEditLastNote(wxCommandEvent& event);
    void OnReparseAllNotes(wxCommandEvent& event);
    void OnSetSource(wxCommandEvent& event);
    void OnConnectDB(wxCommandEvent& event);
    void OnDisconnectDB(wxCommandEvent& event);
    void OnScroll(wxScrollWinEvent& event);
    void OnNextTab(wxCommandEvent& event);
    void OnPrevTab(wxCommandEvent& event);
    void OnCloseTab(wxCommandEvent& event);
    void OnCloseAllTabs(wxCommandEvent& event);
    void OnTabDragBegin(wxAuiNotebookEvent& event);
    void OnTabDragDone(wxAuiNotebookEvent& event);
    void OnToggleFullScreen(wxCommandEvent& event);

    void ConnectDB();
    void DisplayStatusInfo();
    wxString CaptionNewNote() const;
    wxString CaptionFromFilter(const NoteFilter& filter) const;

public:
    // TODO: make these two publicly read-only
    wxString     source;
    vector<Note> edited_notes;

    AppFrame(const wxString& title, const wxPoint& pos, const wxSize& size);

    bool UploadFile(const wxString& filename, const wxString& password);
    bool DownloadFile(const wxString& filename, const wxString& password);

    void AddNotesPanel(const NoteFilter& filter);
    void AddEditsPanel(const NoteFilter& filter);
    void NewNoteDialog();
    void EditNoteDialog(const Note& n);
    void SaveNote(const Note& n);
    bool DeleteNote(const Note note);

    void AddKeywordsPanel();
    void NewKeywordDialog();
    void EditKeywordDialog(const Keyword& keyword);
    bool LoadKeywords();
    void SaveKeyword(const Keyword& k);
    bool DeleteKeyword(const Keyword note);
    void KeywordUsed(int id);

    void NextTab();
    void PrevTab();
    void CloseTab();
    void CloseTab(int i, bool force=false);

    DECLARE_EVENT_TABLE();
};

#endif
